import { ElMessage } from "element-plus";
import { getTokenApi } from "@/http/api_hd";
import { useMain } from "@/store/index";

const useMainStore = useMain();

export const getToken = async (data: any) => {
  let token = sessionStorage.getItem("token");
  if (!token) {
    const userInfo = { ...data };
    const loginRes: any = await getTokenApi(userInfo);
    if (loginRes?.token) {
      token = loginRes?.token;
      sessionStorage.setItem('token', loginRes?.token)
    } else {
      ElMessage.error("登录失败");
    }
  }
  return token;
};


export const closeUIPanel = () => {
  window.BlackHole3D.Graphics.setSysUIPanelVisible(false);
  window.BlackHole3D.Graphics.setGeoCoordVisible(false);
  window.BlackHole3D.Graphics.setViewCubeVisible(false);
}

export const insertDashes = (str:string)=> {
  // 检查字符串长度是否足够
  if (str.length < 20) {
    return str; // 如果字符串长度不足，返回原字符串
  }

  // 在第8位后插入短横线
  let firstPart = str.substring(0, 8) + '-';
  
  // 在第12位后插入短横线
  let secondPart = str.substring(8, 12) + '-';
  
  // 在第16位后插入短横线
  let thirdPart = str.substring(12, 16) + '-';
  
  // 在第20位后插入短横线
  let fourthPart = str.substring(16, 20) + '-';
  
  // 剩余部分
  let remainingPart = str.substring(20);
  
  // 合并部分
  return firstPart + secondPart + thirdPart + fourthPart + remainingPart;
}


